#include "statusctlwidget.h"

StatusCtlWidget::StatusCtlWidget(QWidget *parent)
    : QWidget{parent}
{
    // setStyleSheet("background-color: Grey;");
    setStyleSheet("background-color: Grey;");

    // 这是整个状态区域的垂直布局
    QVBoxLayout *layoutStatusInfo = new QVBoxLayout(this);

    // DeviceInfoWidget->setGeometry(statusWidgetRect.x(), statusWidgetRect.y(), statusWidgetRect.width(), statusWidgetRect.height()/6);
    // DeviceInfoWidget->setStyleSheet("background-color: Yellos;");

    // 状态区域的划分
    DeviceInfoWidget = new QWidget(this);
    StatusInfoWidget = new QWidget(this);
    SetInfoWidget = new QWidget(this);
    CtlBtnWidget = new QWidget(this);
    OperatorInfoWidget = new QWidget(this);


    layoutStatusInfo->addWidget(DeviceInfoWidget, 1);
    layoutStatusInfo->addWidget(StatusInfoWidget, 2);
    layoutStatusInfo->addWidget(SetInfoWidget, 2);
    layoutStatusInfo->addWidget(CtlBtnWidget, 2);
    layoutStatusInfo->addWidget(OperatorInfoWidget, 3);

    // 修改布局样式
    QString styleSheet = "QWidget { border: 2px solid red; }";
    QWidget *DeviceTypeWidget = new QWidget(this);
    // DeviceTypeWidget->setStyleSheet(styleSheet);

    // QGroupBox *DeviceTypeGroup = new QGroupBox(DeviceTypeWidget);
    // DeviceTypeGroup->setTitle(" 设 备 类 型 : ");

    QVBoxLayout *DeviceTypeLayout = new QVBoxLayout(DeviceTypeWidget);
    DeviceTypeLayout->setContentsMargins(50, 20, 10, 10);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceTypeLayout->setSpacing(20);
    QRect rectPost = DeviceTypeLayout->geometry();
    qDebug("Shuai(20241122) post.X=%d post.Y=%d post.Width=%d post.Height=%d", rectPost.x(), rectPost.y(), rectPost.width(), rectPost.height());
    DeviceTypeLayout->setAlignment(Qt::AlignVCenter);
    QLabel *labDeviceType = new QLabel();
    labDeviceType->setText(" 设 备 类 型 : ");
    labDeviceType->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    // labDeviceType->setStyleSheet("QLabel { font-size: 16pt; color: red; }");
    labDeviceType->setFixedWidth(150);
    QComboBox *comboxDeviceType = new QComboBox();
    comboxDeviceType->setFixedHeight(30);
    comboxDeviceType->setFixedWidth(300);
    comboxDeviceType->addItem("SK-O330-Pro");
    comboxDeviceType->addItem("SK-O330");
    comboxDeviceType->addItem("SK-O001-Pro");
    comboxDeviceType->addItem("SK-O002-Pro");
    comboxDeviceType->setEditable(true);
    comboxDeviceType->setStyleSheet("QComboBox {" "font-size: 16px;" /** 设置字体大小 */ " color: red;" /** 设置字体颜色 */ "}"
        "QComboBox QAbstractItemView {" " selection-background-color: yellow;"  /** 设置选中项的背景颜色 */ " selection-color: black;"  /** 设置选中项的字体颜色 */ "}" );
    DeviceTypeLayout->addWidget(labDeviceType);
    DeviceTypeLayout->addWidget(comboxDeviceType);
    DeviceTypeLayout->addStretch(1);

    QWidget *DeviceOnlineWidget = new QWidget(this);
    // DeviceOnlineWidget->setStyleSheet(styleSheet);
    QVBoxLayout *DeviceOnlineLayout = new QVBoxLayout(DeviceOnlineWidget);
    DeviceOnlineLayout->setContentsMargins(50, 20, 10, 10);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceOnlineLayout->setSpacing(20);
    DeviceOnlineLayout->setAlignment(Qt::AlignVCenter);
    QLabel *labDeviceOnline = new QLabel();
    labDeviceOnline->setText(" 在 线 设 备 : ");
    labDeviceOnline->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    // labDeviceOnline->setStyleSheet("QLabel { font-size: 16pt; color: red; }");
    labDeviceOnline->setFixedWidth(150);

    QComboBox *comboxDeviceOnline = new QComboBox();
    comboxDeviceOnline->addItem("SK-O330-Pro");
    comboxDeviceOnline->addItem("SK-O330");
    comboxDeviceOnline->addItem("SK-O001-Pro");
    comboxDeviceOnline->addItem("SK-O002-Pro");
    comboxDeviceOnline->setStyleSheet("QComboBox {" "font-size: 16px;" /** 设置字体大小 */ " color: red;" /** 设置字体颜色 */ "}"
                                    "QComboBox QAbstractItemView {" " selection-background-color: yellow;"  /** 设置选中项的背景颜色 */ " selection-color: black;"  /** 设置选中项的字体颜色 */ "}" );
    comboxDeviceOnline->setFixedHeight(30);
    comboxDeviceOnline->setFixedWidth(300);
    DeviceOnlineLayout->addWidget(labDeviceOnline);
    DeviceOnlineLayout->addWidget(comboxDeviceOnline);
    DeviceOnlineLayout->addStretch(1);


    QGroupBox *DeviceStatusGroup = new QGroupBox();
    DeviceStatusGroup->setFixedHeight(40);
    DeviceStatusGroup->setFixedWidth(200);
    DeviceStatusGroup->setStyleSheet("QGroupBox { border: none; }");
    QHBoxLayout *pbtnLight = new QHBoxLayout(DeviceStatusGroup);
    pbtnLight->setAlignment(Qt::AlignHCenter);
    pbtnLight->setContentsMargins(0, 0, 0, 0);  // 设置布局内边距为0，确保按钮紧密排列
    pbtnLight->setSpacing(20);

    QPushButton *pbtnStatusRun = new QPushButton();
    pbtnStatusRun->setText("Run"); // 如果不需要文本，可以设置为空字符串
    pbtnStatusRun->setFixedSize(36, 36); // 设置按钮的大小为固定值，这里设置为50x50的圆形

    // // 使用样式表设置按钮为圆形并填充红色
    QString pbtnStyleSheet = "QPushButton {" "border-radius: 18px;" /** 设置圆角半径 */ "background-color: red;" /** 设置背景颜色 */  "}";
    QString pbtnReadyStyle = "QPushButton {" "border-radius: 18px;" /** 设置圆角半径 */ "background-color: White;" /** 设置背景颜色 */ "}";
    QString pbtnNormalStyle = "QPushButton {" "border-radius: 18px;" /** 设置圆角半径 */ "background-color: White;" /** 设置背景颜色 */ "}";
    pbtnStatusRun->setStyleSheet(pbtnStyleSheet);

    QPushButton *pbtnStatusStop = new QPushButton();
    pbtnStatusStop->setText("Stop"); // 如果不需要文本，可以设置为空字符串
    pbtnStatusStop->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    pbtnStatusStop->setFixedSize(36, 36); // 设置按钮的大小为固定值，这里设置为50x50的圆形
    pbtnStatusStop->setStyleSheet(pbtnNormalStyle);


    QPushButton *pbtnStatusReady = new QPushButton();
    pbtnStatusReady->setText("Ready"); // 如果不需要文本，可以设置为空字符串
    pbtnStatusReady->setFixedSize(36, 36); // 设置按钮的大小为固定值，这里设置为50x50的圆形
    pbtnStatusReady->setStyleSheet(pbtnReadyStyle);

    pbtnLight->addWidget(pbtnStatusRun);
    pbtnLight->addWidget(pbtnStatusReady);
    pbtnLight->addWidget(pbtnStatusStop);

    // DeviceStatusGroup->setTitle(" 设 备 运 行 状 态 : ");
    QWidget *DeviceStatusWidget = new QWidget(this);
    // DeviceStatusWidget->setStyleSheet(styleSheet);
    QVBoxLayout *DeviceStatusLayout = new QVBoxLayout(DeviceStatusWidget);
    DeviceStatusLayout->setContentsMargins(50, 20, 10, 10);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceStatusLayout->setSpacing(20);
    QLabel *labDeviceStatus = new QLabel();
    labDeviceStatus->setText(" 设 备 运 行 状 态 : ");
    labDeviceStatus->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    labDeviceStatus->setFixedWidth(200);
    DeviceStatusLayout->addWidget(labDeviceStatus);
    DeviceStatusLayout->addWidget(DeviceStatusGroup);
    DeviceStatusLayout->addStretch(1);

    // 设备区域做一个水平布局
    QHBoxLayout *DeviceLayout = new QHBoxLayout(DeviceInfoWidget);
    DeviceLayout->setContentsMargins(0, 0, 0, 0);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceLayout->setSpacing(0);
    DeviceLayout->setAlignment(Qt::AlignCenter);
    DeviceLayout->addWidget(DeviceTypeWidget, 1);
    DeviceLayout->addWidget(DeviceOnlineWidget, 1);
    DeviceLayout->addWidget(DeviceStatusWidget, 1);

    // 实时状态数据展示
    QVBoxLayout *DeviceRealTime = new QVBoxLayout(StatusInfoWidget);
    DeviceRealTime->setContentsMargins(0, 0, 0, 0);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceRealTime->setSpacing(0);
    QWidget *DeviceTimeWidget = new QWidget(this);
    QWidget *DeviceSpeedWidget = new QWidget(this);
    // DeviceTimeWidget->setStyleSheet(styleSheet);
    // DeviceSpeedWidget->setStyleSheet(styleSheet);
    DeviceRealTime->addWidget(DeviceTimeWidget);
    DeviceRealTime->addWidget(DeviceSpeedWidget);

    QRect rectPost1 = DeviceTimeWidget->geometry();
    qDebug("Shuai(20241122) post.X=%d post.Y=%d post.Width=%d post.Height=%d", rectPost1.x(), rectPost1.y(), rectPost1.width(), rectPost1.height());

    QHBoxLayout *DeviceRealTimeElem = new QHBoxLayout(DeviceTimeWidget);
    DeviceRealTimeElem->setContentsMargins(40, 0, 0, 0);
    DeviceRealTimeElem->setSpacing(20);
    DeviceRealTimeElem->setAlignment(Qt::AlignLeft);
    QLabel *labTimeName = new QLabel(" 当 前 步 骤 可 执 行 时 间: ");
    labTimeName->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    DeviceRealTimeElem->addWidget(labTimeName);

    QLCDNumber *lcd = new QLCDNumber(this);
    lcd->setDigitCount(8); // 设置显示的数字位数为
    lcd->setMode(QLCDNumber::Dec); // 设置为十进制模式
    lcd->setSegmentStyle(QLCDNumber::Filled); // 设置显示样式为填充样式
    lcd->setStyleSheet("color: White; background-color: Grey;"); // 设置颜色
    lcd->setFixedSize(200, 50);
    lcd->display("00:30:00");

    DeviceRealTimeElem->addWidget(lcd);

    QHBoxLayout *DeviceRealSpeedElem = new QHBoxLayout(DeviceSpeedWidget);
    DeviceRealSpeedElem->setContentsMargins(40, 0, 0, 0);
    DeviceRealSpeedElem->setSpacing(20);
    DeviceRealSpeedElem->setAlignment(Qt::AlignLeft);
    QLabel *labSpeedName = new QLabel(" 当 前 转 速 : ");
    labSpeedName->setFixedSize(200, 50);
    labSpeedName->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    DeviceRealSpeedElem->addWidget(labSpeedName);

    QLineEdit *lineEdt = new QLineEdit(this);
    lineEdt->setAlignment(Qt::AlignCenter);
    lineEdt->setText("00");
    lineEdt->setStyleSheet("QLineEdit { font-size: 16pt; color: white; }");
    // lineEdt->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    lineEdt->setFixedSize(100, 50);
    DeviceRealSpeedElem->addWidget(lineEdt);

    QLabel *labSpeedFlg = new QLabel("rpm/min");
    labSpeedFlg->setFixedSize(70, 50);
    labSpeedFlg->setAlignment(Qt::AlignBottom);
    labSpeedFlg->setStyleSheet("QLabel { font-size: 10pt; color: White; }");
    DeviceRealSpeedElem->addWidget(labSpeedFlg);

    // QHBoxLayout *DeviceRealTime = new QHBoxLayout(StatusInfoWidget);

    // 实时状态数据展示结束

    // 摇床控制设置
    QVBoxLayout *DeviceSet = new QVBoxLayout(SetInfoWidget);
    DeviceSet->setContentsMargins(0, 0, 0, 0);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceSet->setSpacing(0);


    DeviceTimeSetWidget = new QWidget(this);
    DeviceSpeedSetWidget = new QWidget(this);
    // DeviceTimeSetWidget->setStyleSheet(styleSheet);
    // DeviceSpeedSetWidget->setStyleSheet(styleSheet);
    DeviceSet->addWidget(DeviceTimeSetWidget);
    DeviceSet->addWidget(DeviceSpeedSetWidget);

    QHBoxLayout *DeviceRealTimeSetElem = new QHBoxLayout(DeviceTimeSetWidget);
    DeviceRealTimeSetElem->setContentsMargins(40, 0, 0, 0);
    DeviceRealTimeSetElem->setSpacing(20);
    DeviceRealTimeSetElem->setAlignment(Qt::AlignLeft);
    QLabel *labTimeSet = new QLabel(" 定 时 设 置 : ");
    labTimeSet->setFixedSize(200, 50);

    labTimeSet->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    DeviceRealTimeSetElem->addWidget(labTimeSet);

    // 这里添加一个LineEdit
    lineTimeEdit = new QLineEdit(this);
    // lineTimeEdit->setStyleSheet();
    lineTimeEdit->setText("30");
    // QPalette paletteTime = lineTimeEdit->palette();
    // paletteTime.setColor(QPalette::WindowText, QColor(Qt::white)); // 设置字体颜色为红色
    // lineTimeEdit->setPalette(paletteTime);
    lineTimeEdit->setStyleSheet("QLineEdit { font-size: 16pt; color: white; }");

    // lineTimeEdit->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    lineTimeEdit->setAlignment(Qt::AlignCenter);
    lineTimeEdit->setFixedSize(200, 50);
    lineTimeEdit->setFixedWidth(100);
    DeviceRealTimeSetElem->addWidget(lineTimeEdit);

    QLabel *labTimeFlg = new QLabel("min");
    labTimeFlg->setFixedSize(70, 50);
    labTimeFlg->setAlignment(Qt::AlignBottom);
    labTimeFlg->setStyleSheet("QLabel { font-size: 10pt; color: White; }");
    DeviceRealTimeSetElem->addWidget(labTimeFlg);


    QHBoxLayout *DeviceSpeedSetElem = new QHBoxLayout(DeviceSpeedSetWidget);
    DeviceSpeedSetElem->setContentsMargins(40, 0, 0, 0);
    DeviceSpeedSetElem->setSpacing(20);
    DeviceSpeedSetElem->setAlignment(Qt::AlignLeft);
    QLabel *labSpeedSet = new QLabel(" 设 置 转 速 : ");
    labSpeedSet->setFixedSize(200, 50);
    labSpeedSet->setStyleSheet("QLabel { font-size: 16pt; color: White; }");
    DeviceSpeedSetElem->addWidget(labSpeedSet);

    lineSpeedEdt = new QLineEdit(this);
    lineSpeedEdt->setAlignment(Qt::AlignCenter);
    lineSpeedEdt->setText("100");
    lineSpeedEdt->setStyleSheet("QLineEdit { font-size: 16pt; color: White; }");
    lineSpeedEdt->setFixedSize(100, 50);
    DeviceSpeedSetElem->addWidget(lineSpeedEdt);

    QLabel *labSpeedSetFlg = new QLabel("rpm/min");
    labSpeedSetFlg->setFixedSize(70, 50);
    labSpeedSetFlg->setAlignment(Qt::AlignBottom);
    labSpeedSetFlg->setStyleSheet("QLabel { font-size: 10pt; color: White; }");
    DeviceSpeedSetElem->addWidget(labSpeedSetFlg);
    // 摇床控制设置结束

    // 摇床控制按钮布局
    QVBoxLayout *DeviceCtlBtn = new QVBoxLayout(CtlBtnWidget);
    DeviceCtlBtn->setContentsMargins(0, 0, 0, 0);  // 设置布局内边距为0，确保按钮紧密排列
    DeviceCtlBtn->setSpacing(0);
    QWidget *DeviceSingleCtlWidget = new QWidget(this);
    //QWidget *DeviceMultiCtlWidget = new QWidget(this);
    // DeviceSingleCtlWidget->setStyleSheet(styleSheet);
    //DeviceMultiCtlWidget->setStyleSheet(styleSheet);
    DeviceCtlBtn->addWidget(DeviceSingleCtlWidget);
    //DeviceCtlBtn->addWidget(DeviceMultiCtlWidget);



    SingleCtlElem = new QHBoxLayout(DeviceSingleCtlWidget);
    SingleCtlElem->setContentsMargins(40, 0, 0, 0);
    SingleCtlElem->setSpacing(20);
    SingleCtlElem->setAlignment(Qt::AlignLeft);

    pBtnStart = new QPushButton();
    pBtnStart->setFixedSize(150, 50);
    // pBtnStart->setStyleSheet("QLabel { font-size: 35pt; color: White; }");
    pBtnStart->setFont(QFont("宋体", 20));
    pBtnStart->setText("Start");
    pBtnStart->setStyleSheet("QPushButton {" "border: 1px solid blue;" "color: white;" /** 设置字体颜色 */ "border-radius: 12px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 8px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                    "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    SingleCtlElem->addWidget(pBtnStart);
    // 发指令数据
    // QObject::connect(pBtnStart, &QPushButton::clicked, this, &StatusCtlWidget::);

    pBtnStop = new QPushButton();
    pBtnStop->setFixedSize(150, 50);
    pBtnStop->setFont(QFont("宋体", 20));
    pBtnStop->setText("Stop");
    pBtnStop->setStyleSheet("QPushButton {" "border: 1px solid blue;" "color: white;" /** 设置字体颜色 */ "border-radius: 12px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 8px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                             "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    SingleCtlElem->addWidget(pBtnStop);

    pBtnSave = new QPushButton();
    pBtnSave->setFixedSize(150, 50);
    pBtnSave->setFont(QFont("宋体", 20));
    pBtnSave->setText("Save");
    pBtnSave->setStyleSheet("QPushButton {" "border: 1px solid blue;" "color: white;" /** 设置字体颜色 */ "border-radius: 12px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 8px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                            "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    SingleCtlElem->addWidget(pBtnSave);

    pBtnExist = new QPushButton();
    pBtnExist->setFixedSize(150, 50);
    pBtnExist->setFont(QFont("宋体", 20));
    pBtnExist->setText("Exist");
    pBtnExist->setStyleSheet("QPushButton {" "border: 1px solid blue;" "color: white;" /** 设置字体颜色 */ "border-radius: 12px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 8px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                            "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    SingleCtlElem->addWidget(pBtnExist);

    QString styleSheetGrey = "QWidget { border: 1px solid Grey; }";
    pBtnCtlBox = new QGroupBox();
    pBtnCtlBox->setStyleSheet(styleSheetGrey);
    DeviceCtlBtn->addWidget(pBtnCtlBox);
    pBtnCtlBox->setTitle(" 程 序 控 制 ");
    pBtnCtlBox->setStyleSheet(
        "QGroupBox {"
        "    font-family: Arial, sans-serif;"
        "    font-size: 14px;"
        "    font-weight: bold;"
        "    color: white;" // 设置标题颜色
        "}"
        "QGroupBox::title {"
        "    subcontrol-origin: margin;"
        "    subcontrol-position: top left;"
        "    padding: 0 3px;"
        "    font-size: 16px;" // 可以再次设置标题字体大小，如果需要的话
        "}"
        );
    QHBoxLayout *MultiCtlElem = new QHBoxLayout(pBtnCtlBox);
    MultiCtlElem->setContentsMargins(40, 0, 0, 0);
    MultiCtlElem->setSpacing(20);
    MultiCtlElem->setAlignment(Qt::AlignLeft);

    pBtnAdd = new QPushButton();
    pBtnAdd->setFixedSize(60, 60);
    pBtnAdd->setFont(QFont("宋体", 20));
    pBtnAdd->setText("添加");
    // pBtnAdd->setStyleSheet("QPushButton {" "border: 1px solid blue;" "color: white;" /** 设置字体颜色 */ "border-radius: 12px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
    //                        "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    pBtnAdd->setStyleSheet("QPushButton {" "border: 1px solid yellow;" "color: white;" /** 设置字体颜色 */ "border-radius: 30px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                             "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    MultiCtlElem->addWidget(pBtnAdd);
    QObject::connect(pBtnAdd, &QPushButton::pressed, this, &StatusCtlWidget::AddLineData);


    pBtnDelete = new QPushButton();
    pBtnDelete->setFixedSize(60, 60);
    pBtnDelete->setFont(QFont("宋体", 20));
    pBtnDelete->setText("删除");
    // pBtnAdd->setStyleSheet("QPushButton {" "border: 1px solid blue;" "color: white;" /** 设置字体颜色 */ "border-radius: 12px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
    //                        "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    pBtnDelete->setStyleSheet("QPushButton {" "border: 1px solid white;" "color: white;" /** 设置字体颜色 */ "border-radius: 30px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                           "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    MultiCtlElem->addWidget(pBtnDelete);
    QObject::connect(pBtnDelete, &QPushButton::pressed, this, &StatusCtlWidget::DeleteLineData);

    pBtnImport = new QPushButton();
    pBtnImport->setFixedSize(60, 60);
    pBtnImport->setFont(QFont("宋体", 20));
    pBtnImport->setText("导入");
    pBtnImport->setStyleSheet("QPushButton {" "border: 1px solid white;" "color: white;" /** 设置字体颜色 */ "border-radius: 30px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                              "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    MultiCtlElem->addWidget(pBtnImport);

    pBtnOutPut = new QPushButton();
    pBtnOutPut->setFixedSize(60, 60);
    pBtnOutPut->setFont(QFont("宋体", 20));
    pBtnOutPut->setText("导出");
    pBtnOutPut->setStyleSheet("QPushButton {" "border: 1px solid white;" "color: white;" /** 设置字体颜色 */ "border-radius: 30px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                              "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    MultiCtlElem->addWidget(pBtnOutPut);

    pMultiBtnStart = new QPushButton();
    pMultiBtnStart->setFixedSize(60, 60);
    pMultiBtnStart->setFont(QFont("宋体", 20));
    pMultiBtnStart->setText("启动");
    pMultiBtnStart->setStyleSheet("QPushButton {" "border: 1px solid white;" "color: white;" /** 设置字体颜色 */ "border-radius: 30px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                              "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    MultiCtlElem->addWidget(pMultiBtnStart);

    pMultiBtnStop = new QPushButton();
    pMultiBtnStop->setFixedSize(60, 60);
    pMultiBtnStop->setFont(QFont("宋体", 20));
    pMultiBtnStop->setText("停止");
    pMultiBtnStop->setStyleSheet("QPushButton {" "border: 1px solid white;" "color: white;" /** 设置字体颜色 */ "border-radius: 30px;" /** 设置圆角半径 */ "background-color: gray;" /** 设置背景颜色 */ "padding: 1px;" "}" /** 设置内边距，以确保按钮内容不会紧贴圆角边缘 */
                                  "QPushButton:hover {" /** 可选：设置鼠标悬停时的样式 */ "background-color: lightgray;" "}" "QPushButton:pressed {" /**  可选：设置按钮被按下时的样式 */ "background-color: darkgray;" "}" );
    MultiCtlElem->addWidget(pMultiBtnStop);

    //摇床控制按钮布局结束

    // 摇床多步骤控制参数设置
    QVBoxLayout *layout = new QVBoxLayout(OperatorInfoWidget);

    tableWidget = new QTableWidget(0, 5, this); // 0 rows, 3 columns
    tableWidget->setHorizontalHeaderLabels({"时长(HH:MM)", "速度(100-1500)", "温度(±340°C)", "状态(Ready/Run/Done)", ""});
    tableWidget->horizontalHeader()->setStretchLastSection(true);
    // tableWidget->setStyleSheet("QTableWidget { background-color: grey; }");
    tableWidget->resizeColumnsToContents();
    // tableWidget->setColumnWidth(0, 200);
    tableWidget->horizontalHeader()->setStyleSheet(" QHeaderView::section { background-color: grey; }");
    tableWidget->verticalHeader()->setStyleSheet("QHeaderView::section { background-color: grey; }");

    for (int column = 0; column < tableWidget->columnCount(); ++column) {
        tableWidget->setColumnWidth(column, 150);
    }

    // tableWidget->setSelectionMode(QAbstractItemView::SelectRows);
    // tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection | QAbstractItemView::SelectRows);
    // tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
    // tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
    // tableWidget->setSelectionMode(QAbstractItemView::SelectRows);

    // QObject::connect(tableWidget, &QTableWidget::selectionChanged, this, &StatusCtlWidget::onTableSelectionChanged);
    QObject::connect(tableWidget, &QTableWidget::cellDoubleClicked, this, &StatusCtlWidget::onCellDoubleClicked);



    layout->addWidget(tableWidget);

    // 摇床多步骤控制参数设置结束
    // int rowCount = tableWidget->rowCount();
    // tableWidget->insertRow(0);
    // tableWidget->insertRow(1);
    // tableWidget->insertRow(2);

}

void StatusCtlWidget::mousePressEvent(QMouseEvent *event)
{
    // 首先调用基类的 mousePressEvent 以保持默认行为
    // QTableWidget::mousePressEvent(event);

    // 打印鼠标事件信息
    qDebug() << "Mouse press event at position:" << event->pos();
    qDebug() << "Mouse button pressed:" << event->button();

    // 如果需要，可以在这里添加自定义的处理逻辑
}

void StatusCtlWidget::onCellDoubleClicked(int row, int column)
{
    QTableWidgetItem *item = tableWidget->item(row, column);
    if (item)
    {
        // 修改单元格内容，例如将其设置为新文本
        item->setText("新内容");
    }
}

void StatusCtlWidget::AddLineData()
{
    int rowCount = tableWidget->rowCount();
    tableWidget->insertRow(0);
}

void StatusCtlWidget::DeleteLineData()
{
    // int rowSelect = tableWidget->selectedItems();
    // tableWidget->removeRow(rowSelect);
}

void StatusCtlWidget::SendSignelInstruct()
{
    // 获取指令详细数据
    QString strTime = lineTimeEdit->text();
    int iTimeData = strTime.toInt();

    QString strSpeed = lineSpeedEdt->text();
    int iSpeedData = strSpeed.toInt();

    // 数据组包


}
